<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [lvLabelColon]="false" [formGroup]="formGroup" class="formGroup">
  <lv-form-item>
    <lv-form-label lvRequired>{{ 'common_name_label' | i18n }}</lv-form-label>
    <lv-form-control [lvErrorTip]="nameErrorTip">
      <input lv-input type="text" formControlName="name" />
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{(includes([ResourceType.CNWARE, ResourceType.NUTANIX], resourceType) ? 'common_ip_address_domain_label' : 'common_ip_address_label') | i18n}}
    </lv-form-label>
    <lv-form-control [lvErrorTip]="ipErrorTip">
      <input lv-input type="text" formControlName="ip" />
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>{{ 'common_port_label' | i18n }}</lv-form-label>
    <lv-form-control [lvErrorTip]="portErrorTip">
      <input lv-input type="text" formControlName="port" placeholder="1~65535" />
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>{{
      'common_username_label' | i18n
      }}</lv-form-label>
    <lv-form-control [lvErrorTip]="userNameErrorTip">
      <input lv-input type="text" formControlName="userName" autocomplete="new-password" />
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>{{
      'common_password_label' | i18n
      }}</lv-form-label>
    <lv-form-control [lvErrorTip]="passwordErrorTip">
      <aui-inupt-with-eye formControlName="password" [lvPasteAllowed]="false"></aui-inupt-with-eye>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item *ngIf="includes([ResourceType.CNWARE, ResourceType.NUTANIX], resourceType)">
    <lv-form-label lvRequired>
      {{ 'protection_proxy_host_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <aui-agent-select [lvOptions]="proxyOptions" formControlName="agents" lvValueKey="value" lvMode="multiple">
      </aui-agent-select>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label lvRequired>
      {{'protection_register_vm_rescan_label' | i18n}}
      <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_register_vm_rescan_help_label'| i18n}}"
        lvTooltipPosition="rightTop" class="configform-constraint" lvColorState='true'></i>
    </lv-form-label>
    <lv-form-control [lvErrorTip]="rescanIntervalErrorTip">
      <lv-group [lvColumns]='["auto", "40px"]'>
        <input lv-input type="text" formControlName="rescan_interval_in_sec" />
        <span class="alin-right">{{'common_hour_label' | i18n}}</span>
      </lv-group>
    </lv-form-control>
  </lv-form-item>
  <lv-form-item>
    <lv-form-label>
      {{ 'common_verify_cert_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-switch formControlName="cert"> </lv-switch>
      <div *ngIf="!formGroup.value.cert">
        <i lv-icon="lv-icon-status-warning-info"></i>
        <span class="aui-text-label">
          {{ certTipLabel }}
        </span>
      </div>
    </lv-form-control>
  </lv-form-item>
  <ng-container *ngIf="formGroup.value.cert">
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'protection_fc_cert_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-upload lvAccept=".pem" lvShowUpload="false" [lvFilters]="fcCertFilters" [(lvFiles)]="certFiles"
          (lvChange)="cartChange($event)"></lv-upload>
      </lv-form-control>
    </lv-form-item>
    <lv-form-item>
      <lv-form-label>
        {{ 'system_revocation_list_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-upload lvAccept=".crl" lvShowUpload="false" [lvFilters]="revocationListFilters" [(lvFiles)]="crlFiles"
          (lvChange)="crlChange($event)"></lv-upload>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <lv-form-item *ngIf="!includes([ResourceType.CNWARE, ResourceType.NUTANIX], resourceType)">
    <lv-form-label>
      {{'protection_register_enable_tls_label' | i18n}}
      <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_register_enable_tls_help_label'| i18n}}"
        lvTooltipPosition="rightTop" class="configform-constraint" lvColorState='true'></i>
    </lv-form-label>
    <lv-form-control>
      <lv-switch formControlName="tls_compatible"></lv-switch>
      <div *ngIf="formGroup.value.tls_compatible">
        <i lv-icon="lv-icon-status-warning-info"></i>
        <span class="aui-text-label">
          {{ 'protection_register_vmware_tls_tips_label' | i18n }}
        </span>
      </div>
    </lv-form-control>
  </lv-form-item>
  <!-- cnware过滤虚拟机 -->
  <ng-container *ngIf="includes([ResourceType.CNWARE, ResourceType.NUTANIX], resourceType)">
    <lv-form-item>
      <lv-form-label>
        {{'protection_vm_filter_label' | i18n}}
        <i lv-icon="aui-icon-help" lv-tooltip="{{'protection_cnware_vm_filter_label'| i18n}}"
          lvTooltipPosition="rightTop" class="configform-constraint" lvColorState='true'></i>
      </lv-form-label>
      <lv-form-control>
        <lv-switch formControlName="enableFilter"></lv-switch>
        <div *ngIf="formGroup.value.enableFilter">
          <lv-form-item>
            <lv-form-label lvRequired>{{'protection_key_label' | i18n}}</lv-form-label>
            <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
              <input lv-input type="text" formControlName="filterName" />
            </lv-form-control>
          </lv-form-item>
        </div>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
</lv-form>

<ng-container *ngIf="!includes([ResourceType.CNWARE, ResourceType.NUTANIX], resourceType)">
  <div class="aui-gutter-column-xl"></div>
  <h2 class="dataStore-position">
    <lv-group [lvGutter]="'5px'">
      <span>{{ 'protection_storage_resource_label' | i18n }}</span>
    </lv-group>
  </h2>
  <div>
    <div class="aui-operation">
      <lv-pro-button-group [config]="optItems" [bindData]="tableData?.data"></lv-pro-button-group>
    </div>
    <span class="show-tips">
      <i lv-icon="lv-icon-status-info" class="icon-info" lvColorState="true"></i>
      {{ 'common_fc_add_data_store_label' | i18n }}
    </span>
    <lv-pro-table #dataTable [config]="tableConfig" [data]="tableData"></lv-pro-table>
  </div>
</ng-container>

<ng-template #storageTypeTpl let-item>
  <span lv-overflow>{{item.storageType | textMap:'Device_Storage_Type'}}</span>
</ng-template>